<?php

namespace App\Http\Controllers;

use App\Common\Sql;

class ReadMail extends Base
{

    public function logic()
    {
        $uid     = $this->uid;
        $mail_id = $this->param["mail_id"];
        $row     = Sql::select('t_mail_info', [['id', $mail_id], ['uid', $uid]]);
        if (count($row) == 0) {
            return $this->returnError(1, "参数 mail_id 不匹配.\n");
        }

        if ((int)$row[0]['status'] != 0) {
            return $this->returnError(2, "此邮件已经阅读领取. 不能重复领取.\n");
        }

        $ret = Sql::update('t_mail_info',[['id',$mail_id]],['status',1]);
        if (!$ret) {
            return $this->returnError(3, "领取奖励更新领奖标志失败.");
        }

        //返回成功
        $ret_data             = array();
        $ret_data["gold"]     = $this->get_user_gold($uid);
        $ret_data["diamonds"] = $this->get_user_diamonds($uid);
        return $this->returnData($ret_data);

    }

}

